<?php
/**
 *  作者：梦雨
 *  @ QQ50361804
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
class Home extends Controller
{
    public function _initialize()
    {
        h('phphomeinitialize');
        parent::_initialize();
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录', 'index/index/login');
        }
    }
    //首页
    public function index()
    {
        h('phphomeindex');
        if (!empty(cms('uindex'))) {
            return view(cms('uindex') . '.html');
        }
        if (file_exists(WEB() . 'home_index.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_index.html')) {
                 return view(pc() . 'home_index.html');
            } else {
                return view('app/template/pc/default_pc/home_index.html');
            }
        }
    }
    //基本设置
    public function set()
    {
        h('phphomeset');
        if (!empty(cms('uset'))) {
            return view(cms('uset') . '.html');
        }
        if (file_exists(WEB() . 'home_set.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_set.html')) {
                return view(pc() . 'home_set.html');
            } else {
                return view('app/template/pc/default_pc/home_set.html');
            }
        }
    }
    //投稿
    public function add()
    {
        h('phphomeadd');
        $id = input('id');
        $this->assign('id', $id);
        if (stripos('0,' . qxz(session('userid'), 2), '3') == '') {
            $this->error('暂无权限');
        }
        $model = fun_sc_p('model', array('id' => $id), 'name');
        $this->assign('model', $model);
        if (!empty(cms('uadd'))) {
            return view(cms('uadd') . '.html');
        }
        if (file_exists(WEB() . 'home_add.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_add.html')) {
                return view(pc() . 'home_add.html');
            } else {
                return view('app/template/pc/default_pc/home_add.html');
            }
        }
    }
    //编辑
    public function edit()
    {
        h('phphomeedit');
        $id = input('id');
        $this->assign('id', $id);
        $model = m(input('model'));
        $this->assign('model', $model);
        $c = Db::name(m(input('model')))->where('id', input('id'))->find();
        $this->assign('c', $c);
        if (fun_sc_p('cate', array('id' => $c['tid']), 'edit') == 0) {
            $this->error('当前分类下的内容不允许编辑');
        }
        if (!empty(cms('uedit'))) {
            return view(cms('uedit') . '.html');
        }
        if (file_exists(WEB() . 'home_edit.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_edit.html')) {
                return view(pc() . 'home_edit.html');
            } else {
                return view('app/template/pc/default_pc/home_edit.html');
            }
        }
    }
    //我的发布
    public function contribute()
    {
        h('phphomecontribute');
        $id = input('id');
        $this->assign('id', $id);
        $model = fun_sc_p('model', array('id' => $id), 'name');
        $this->assign('model', $model);
        if (!empty(cms('ucontribute'))) {
            return view(cms('ucontribute') . '.html');
        }
        if (file_exists(WEB() . 'home_contribute.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_contribute.html')) {
                return view(pc() . 'home_contribute.html');
            } else {
                return view('app/template/pc/default_pc/home_contribute.html');
            }
        }
    }
    //我的消息
    public function xiaoxi()
    {
        h('phphomexiaoxi');
        if (!empty(cms('uxiaoxi'))) {
            return view(cms('uxiaoxi') . '.html');
        }
        if (file_exists(WEB() . 'home_xiaoxi.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_xiaoxi.html')) {
                return view(pc() . 'home_xiaoxi.html');
            } else {
                return view('app/template/pc/default_pc/home_xiaoxi.html');
            }
        }
    }
    //我的评论
    public function comment()
    {
        h('phphomecomment');
        if (!empty(cms('ucomment'))) {
            return view(cms('ucomment') . '.html');
        }
        if (file_exists(WEB() . 'home_comment.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_comment.html')) {
                return view(pc() . 'home_comment.html');
            } else {
                return view('app/template/pc/default_pc/home_comment.html');
            }
        }
    }
    //我的收藏
    public function shoucang()
    {
        h('phphomeshoucang');
        if (!empty(cms('ushoucang'))) {
            return view(cms('ushoucang') . '.html');
        }
        if (file_exists(WEB() . 'home_shoucang.html')) {
            return view();
        } else {
            if (file_exists('app/template/pc/' . MBPC() . '/home_shoucang.html')) {
                return view(pc() . 'home_shoucang.html');
            } else {
                return view('app/template/pc/default_pc/home_shoucang.html');
            }
        }
    }
}